package org.coc.betterchicago.rest;

import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class ErrorResource extends ServerResource {

	@Get("json")
	public String handleGet() {
		try {
			return error().getText();
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	private JsonRepresentation error() {
		JSONObject json = new JSONObject();
		try {
			json.put("error", "Unknown error occured.");
		} catch (JSONException e) {
			return new JsonRepresentation("{\"error\": \"Unknown error occured.\"}");
		}
		JsonRepresentation jsonRep = new JsonRepresentation(json);
		return jsonRep;
	}
}